CS50 Call Stack


Call Stack

int fact(int n)
{
    if (n==1)
        return 1;
    else
        return n * fact(n - 1);
}
int main(void)
{
    printf("%i\n", fact(5));
}

This recursive function would look like this in Stack Memory

// a lot of call stack, which will release as the function done one by one from the top one.

fact(1)
fact(2)
fact(3)
fact(4)
fact(5)
printf()
main()
#cs50 #memory #stack #call stack







你可能感興趣的文章

原型與繼承(1) - 建構式函式 & 閉包

原型與繼承(1) - 建構式函式 & 閉包

新版 Python 在 PyCharm 無法正確判讀與除錯處理

新版 Python 在 PyCharm 無法正確判讀與除錯處理

程式碼真正想跟你說的話

程式碼真正想跟你說的話






留言討論